import { createRouter, createWebHashHistory } from 'vue-router'

// 路由配置
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('@/views/index/Home.vue'),
    meta: {
      title: '首页'
    }
  },
  {
    path: '/account',
    name: 'Account',
    component: () => import('@/views/index/Account.vue'),
    meta: {
      title: '账户管理'
    }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('@/views/index/Settings.vue'),
    meta: {
      title: '系统设置'
    }
  },
  {
    path: '/certificate',
    name: 'Certificate',
    component: () => import('@/views/index/certificate/index.vue'),
    meta: {
      title: '证书管理'
    }
  }
]

// 创建路由实例 - 使用hash模式
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - 账户系统`
  }
  next()
})

export default router